package com.sodaopen.study.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sodaopen.study.entity.ApiResult;
import com.sodaopen.study.entity.Locked;
import com.sodaopen.study.service.LockedService;

@Controller
public class LockController {

    @Autowired
    private LockedService lockedService;

    @GetMapping("/locked/list")
    public String listLocked(){
        return "locked";
    }

    @GetMapping("/api/locked/list")
    @ResponseBody
    public Object getListLocked(){

        ApiResult result = new ApiResult();
        try{
            List<Locked> list = lockedService.findAll();
            result.setCode(0);
            result.setData(list);
        }catch (Exception e){
            result.setCode(1);
            result.setMsg("数据请求失败");
        }
        return result;
    }

    @GetMapping("/api/locked/delete")
    @ResponseBody
    public Object deleteLocked(Integer userId, Integer courseId){

        ApiResult result = new ApiResult();
        try{
            lockedService.deleteLocked(userId, courseId);
            result.setCode(0);
            result.setMsg("数据请求成功");
        }catch (Exception e){
            result.setCode(1);
            result.setMsg("数据请求失败");
        }
        return result;
    }


}
